package com.back_end.Reflection;

import com.TestDemo.TestBean;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

public class TestGetGeneric {



    public void test01(Map<String, TestBean> map, List<TestBean> list){

        System.out.println("test01Method.");
    }


    public Map<String,TestBean> test02(){
        System.out.println("test02Method.");
        return null;
    }

    public static void main(String[] args) throws NoSuchMethodException {


        Method test01Method = TestGetGeneric.class.getMethod("test01", Map.class, List.class);

        Type[] genericParameterTypes = test01Method.getGenericParameterTypes();

        System.out.println("genericParameterTypes:" + genericParameterTypes);
        for (Type genericParameterType : genericParameterTypes) {
            System.out.println("***" + genericParameterType);
            if(genericParameterType instanceof ParameterizedType){
                Type[] actualTypeArguments = ((ParameterizedType) genericParameterType).getActualTypeArguments();
                for (Type actualTypeArgument : actualTypeArguments) {
                    System.out.println("---" + actualTypeArgument);
                }
            }
        }


        System.out.println("=======================");


        Method test02Method = TestGetGeneric.class.getMethod("test02", null);
            Type genericReturnType = test02Method.getGenericReturnType(); // return只有一个返回值吧？！
        if (genericReturnType instanceof ParameterizedType){
            Type[] actualTypeArguments = ((ParameterizedType) genericReturnType).getActualTypeArguments();
            for (Type actualTypeArgument : actualTypeArguments) {
                System.out.println("---" + actualTypeArgument);
            }
        }


    }



}
